package kgame5.pbe.atlantic.manager {
	import kgame5.k2d.Camera2D;
	import kgame5.k2d.MouseInput2D;
	import kgame5.pbe.engine.core.IAnimatedObject;

	import flash.display.DisplayObject;
	import flash.display.Sprite;

	/**
	 * @author max
	 * 2010-12-13
	 * 
	 * 游戏视图管理器,
	 * 注意Vector3D是左手坐标，2D时之用x,y,z，不要用内积外积
	 * -----------X
	 * |
	 * |
	 * |
	 * Y
	 * 
	 * 
	 */
	public class View2DManager implements IAnimatedObject {
		
		private var mc_c:Sprite;
		
		public var camera:Camera2D;//这个可被外部访问，设置摄像机的视野和世界大小,直接暴露被外部访问并不是很好
		
		private var mouseInput:MouseInput2D;//拖拽屏幕用的,也可以用来定位点击打的是屏幕的哪个位置
		
		
		private var aLayer:Array;//
		
		public function View2DManager() {
			
		}
		
		public function init(mc_c:Sprite,viewWidth:int,viewHeight:int,worldWidth:int,worldHeight:int):void{
			
			this.mc_c=mc_c;
		
			//摄像机
			camera =new Camera2D(mc_c);
			camera.setViewSize(viewWidth, viewHeight);
			camera.setWorldSize(worldWidth,worldHeight);
			
			//鼠标拖拽屏幕
			mouseInput=new MouseInput2D(mc_c,camera);
			
			//各个图层
			aLayer=[];
			for(var i:int=0;i<16;i++){
				var mc_layer:Sprite=new Sprite();
				mc_c.addChild(mc_layer);
				aLayer.push(mc_layer);
			}
		}
		
		public function onFrame(deltaTime : Number) : void {	
			camera.update();
		}
		
		public function addNode(mc:DisplayObject,layerID:int):void{
			(aLayer[layerID] as Sprite).addChild(mc);
			
			
		}
		
		//没做安全性检查，出错会报错的
		public function removeNode(mc:DisplayObject,layerID:int):void{
			(aLayer[layerID] as Sprite).removeChild(mc);
			
		}
	}//end of class
}
